
#import <UIKit/UIKit.h>

#import "Vector3.h"
#import "Rendereble.h"

typedef struct 
{
	Vector3		size;
	Vector3		hotspot;
	Vector3		textCoord[2];	// [0] - LeftTop, [1] - RightBottom	
}SpriteFrameDef;

typedef struct 
{
//	const char		*textureFilename;
	
	SpriteFrameDef	*framesArray;
	int				framesCount;

	bool			loop;
	bool			reverse;
	float			frameFreq;	// = 1/frameRate
}SpriteAnimDef;

@interface Sprite : Rendereble 
{
	Texture		*texture;
	
	Vector3		pos;
	Vector3		size;
	Vector3		hotspot;

	Vector3		textCoordLeftTop;
	Vector3		textCoordRightBottom;
	
	float		rotateAngle;
	float		scale;
	
	BOOL		hidden;
	
	/*
	 *	Blink
	 */
	BOOL		blink;
	float		blinkFreq;		// Times per second

	float		blinkTimer;
	BOOL		blinkHide;		// YES if sprite in blink-hide phase
	
	// Animaitons
	SpriteAnimDef	*animsArray;
	int				animsCount;
	
	int			currentAnim;
	int			currentFrame;
	
	float		frameTime;
	
	BOOL		play;			// YES - to play anim, NO- to stop.
	BOOL		loop;
}

@property	(readonly)	Texture		*texture;
@property	(assign)	Vector3		pos;
@property	(assign)	Vector3		size;
@property	(assign)	Vector3		hotspot;
@property	(assign)	Vector3		textCoordLeftTop;
@property	(assign)	Vector3		textCoordRightBottom;
@property	(assign)	float		rotateAngle;
@property	(assign)	float		scale;
@property	(assign)	BOOL		hidden;
@property	(assign)	BOOL		play;
@property	(assign)	BOOL		loop;
@property	(assign)	BOOL		blink;
@property	(assign)	float		blinkFreq;


@property (readonly)	int			currentAnimation;
@property (readonly)	int			animationsCount;

@property (readonly)	BOOL		isLastFrame;

+(void)setDefaultHotspot:(Vector3)hotspot;
+(void)setDefaultSize:(Vector3)size;
+(void)setDefaultFrameSize:(Vector3)size;

+(Vector3)defaultHotspot;
+(Vector3)defaultSize;
+(Vector3)defaultFrameSize;

/*
 *	Init with single anim and single frame.
 */
-(id) initWithFileNamed:(NSString*) filename;
-(id) initWithFileName:(NSString*)filename FramesCount:(int)framesCount FramesPerLine:(int)framesPerLine;

/*
 *	Init with animations definition array.
 */
-(id) initWithAnimDefArray:(SpriteAnimDef**)animDefArray TextureFileName:(NSString*)filename;

-(void) setAnimation:(int) animNum;
-(void) setFrame:(int) frameNum;
//-(void) setAnimation:(int)animNum Frame:(int)frameNum;

-(void) setTextCoordLeftTop:(Vector3)leftTop RightBottom:(Vector3)rightBottom;
-(void) setTextCoordPixelsLeftTop:(Vector3)leftTop RightBottom:(Vector3)rightBottom;

-(void) updateWithTime:(float)time DeltaTime:(float)delta;

@end
